{extend name="public:_base" /}
{block name="css"}
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/uploadify/uploadify.css">
{/block}
{block name="js"}
{load href="__STATIC__/admin/hui/lib/My97DatePicker/4.8/WdatePicker.js" /}
{load href="__STATIC__/admin/login/js/jquery-1.4.2.min.js" /}
{include file="public/_validform"}
<!--上传配置 -->
<script src="__STATIC__/admin/js/upfile.js" type="text/javascript"></script>

<!-- 配置文件 -->
<script type="text/javascript" src="__STATIC__/admin/hui/lib/ueditor/1.4.3/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__STATIC__/admin/hui/lib/ueditor/1.4.3/ueditor.all.js"></script>

<script type="text/javascript">
    var ue = UE.getEditor('editor');
    $("[name='cid']").find("[value='{$data.cid ?? ''}']").attr("selected", true);
    upload_image('image','','300','300','500');
    var URL = {
        uploader: '{:url('Upload/image')}',
        swf:'__STATIC__/admin/uploadify/uploadify.swf',
        ROOT:'__PUBLIC__/uploads/image',
    }

    $(document).ready(function(e) {
        dateformat('starttime', 0);
        dateformat('deadline', 7);
        number();
        $("#submit_survey").click(function(){
            var cid = $('#contentid').val();
            var title = $('#questionnaire_til').val();
            if (title == '您可以在这里创建您的考试题目，同时对考试活动加以说明') {
                title = '';
            }
            if (title == '') {
                alert('请填写考试标题');
                return false;
            }
            save_survey();
            return false;
        });

        $(".del").live("click",function(){
            delimage($(this));
        });

        $(".optionul li .pic").live('mouseenter',function(){
            $(this).children("img").show();
        });

        $(".optionul li .pic").live('mouseleave',function(){
            $(this).children("img").hide();
        });

    });

    function delimage(obj){
        obj.parent().addClass("hidden");
        obj.parent().prev("span").removeClass("hidden");
        obj.parent().parent().find("input[class='image_class']").val("");
    }

    function save_survey()
    {
        $.post("{pigcms::U('Research/saveInfo',array('token' => $token))}", $('#survey_form').serialize(), function(response){
            if (response.error_code) {
                alert(response.msg);
                return false;
            } else {
                location.href="{pigcms::U('Research/index',array('token' => $token))}";
                return false;
            }
        }, 'json');
    }

    function clear_form()
    {
        $("input").val('');
        $("textarea").val('');
        $("select").val('');
        $("#infotype").val(3);
        $("#tag_image_show").hide();
        $("#explanation").hide();
    }

    /*添加选项*/
    function number(){
        var i = 0;
        $(".optionul li").each(function(){
            $(this).find("input[name='userfile']").attr("id","userfile_" + i).live("change",function(){
                uploadimage($(this).attr("id"));
            });
            i ++;
        })
    }
    $("#userfile").change(function(){
        upload_image();
    });
    function upload_cancel()
    {
        $('#tag_image_show').hide();
        $("#cover_image").val('');
        $("#file_name").val('');
        $("#show_name").html('');
        $("#tag_image_src").attr('src', '').hide();
        $("#file_partpath").val('');
    }

    $(".orange_tips a.close").click(function(){
        $(".orange_tips").remove();
    })

    /*添加选项*/
    var a = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
    function letters(){
        $(".question_box ul li").each(function(){
            $(this).find("span:first").html(a[$(this).index()]);
            $(this).find(".question").attr('name', 'oldquestion['+$(this).parent().attr('id')+']['+$(this).index()+']').val(a[$(this).index()]);
            $(this).find(".txt").attr('name', 'option['+$(this).parent().attr('id')+']['+$(this).index()+']');
            $(this).find(".hide_txt").attr('name', 'oid['+$(this).parent().attr('id')+']['+$(this).index()+']');
            $(this).find(".image_class").attr('name', 'image['+$(this).parent().attr('id')+']['+$(this).index()+']');
        });
        $(".topic_box .question_box").each(function(){
            $(this).find(".question_info span u").html($(this).index() + 1);
        });
        $('#question_info_1 .box_del').remove();
        $('.question_box ul li .txt').focus(function(){
            $(this).next().show();
        });

    }

    letters();

//    $(".question_box ul li .list_del").live('click',function(){
//        $(this).parents("li").remove();
//        letters();
//    });


//    $(".question_box .bot_add a.btnGrayS").live('click',function(){
//        var t = '<li><span>A</span><u>选项：</u><input type="text" class="question"><input type="hidden" class="hide_txt"> <input type="text" class="txt"/><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>';
//        if($(this).parents(".question_box").find("ul li").size() <= 25){
//            $(this).parents(".question_box").find("ul").append(t);
//            letters();
//            number();
//        }else{
//            alert("您添加的数量够您用一辈子了！");
//        }
//    });
    /*添加选项结束*/

    /*添加题目和删除题目*/
    $(".add_questio a").click(function(){
        var t = '<div class="question_box"><p class="question_info"><span>问题<u>1</u>：</span><input type="text" class="txt" value="请填写问题的题目" />'
            +'<input type="text" class="answer" value="请填写题目的答案">'
            +'<input type="checkbox" class="checkd" value="1" /><input type="hidden" id="qid[1]" ><label> 允许多选</label><select class="typeselect"><option value="0">单选</option><option value="1">多选</option><option value="2">自由填写</option></select>&nbsp;&nbsp;<a href="javascript:;" class="box_del">删除</a></p>'
            +'<span class="insert_pic hidden">图片建议尺寸：150*100</span><ul id="1" class="optionul">'
            +'<li><span>A</span><u>选项：</u><input type="text" class="question"><input type="hidden" class="hide_txt"> <input type="text" class="txt" /><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>'
            +'<li><span>B</span><u>选项：</u><input type="text" class="question"><input type="hidden" class="hide_txt" > <input type="text" class="txt" /><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>'
            +'<li><span>C</span><u>选项：</u><input type="text" class="question"><input type="hidden" class="hide_txt" > <input type="text" class="txt" /><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>'
            +'<li><span>D</span><u>选项：</u><input type="text" class="question"><input type="hidden" class="hide_txt" > <input type="text" class="txt" /><input type="hidden" class="image_class" /> <a class="list_del" href="javascript:;" title="删除这个选项">×</a><span class="no_pic hidden"><a href="javascript:;" class="up"><i></i>插入图片<input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100"></a><div class="uppic_prompt">图片建议尺寸：<span>150*100</span><div class="caret_Up"><em>◆</em><span>◆</span></div></div></span><span class="pic hidden" style="width:auto"><a href="javascript:;">../fjdskjf.jpg</a><img src="" width="150" height="100"><a href="javascript:;" class="del">×</a></span></li>'
            +'</ul><p class="bot_add"><a href="javascript:;" class="btnGrayS vm bigbtn"><img src="/images/product/add.png" width="16" class="vm">再添加一个选项</a></p></div>';
        $(".add_questio").before(t);
        $(".question_box:last").find("li:eq(3)").nextAll().remove();
        $(".question_box").each(function() {
            //$(this).find("u").html($(this).index());
            $(this).find(".question_info .txt").attr('name', 'question['+$(this).index()+']');
//            $(this).find(".question_info .checkd").attr('name', 'ismulti['+$(this).index()+']');
            $(this).find(".question_info .answer").attr('name', 'answer['+$(this).index()+']');
            $(this).find(".question_info .typeselect").attr('name', 'ismulti['+$(this).index()+']');
            $(this).find(".question_info .checkd").attr('id', 'ismulti_'+$(this).index());
            $(this).find(".question_info label").attr('for', 'ismulti_'+$(this).index());
            $(this).find(".question_info .hide_qid").attr('name', 'qid['+$(this).index()+']');
            $(this).find("ul").attr('id', $(this).index());
        });
        letters();
        number();
    })
    $(".box_del").live('click',function(){
        $(this).parents(".question_box").remove();
        $(".question_box").each(function() {
            //$(this).find("u").html($(this).index());
        });
        letters();
        number();
    })
    /*添加题目和删除题目结束*/

    /*input默认文字显示、消失*/
    $("#questionnaire_til").focusin(function(){
        if($(this).val() == "您可以在这里创建您的考试题目，同时对考试活动加以说明"){
            $(this).val("");
            $(this).css("color","#666");
        }
    }).focusout(function(){
        if($(this).val() == ""){
            $(this).val("您可以在这里创建您的考试题目，同时对考试活动加以说明");
            $(this).css("color","#999");
        }
    })
    $(".question_box p .txt").live('focusin',function(){
        if($(this).val() == "请填写问题的题目"){
            $(this).val("");
            $(this).css("color","#666");
        }
    }).live('focusout',function(){
        if($(this).val() == ""){
            $(this).val("请填写问题的题目");
            $(this).css("color","#999");
        }
    });


    function dateformat(id, day){
        var date = new Date();
        date.setDate(date.getDate()+day);
        var deadline = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();
        $("#" + id).val(deadline);
    }
</script>
{/block}
{block name="main"}
<div class="page-container">

    <form class="form form-horizontal" action="{:url(\''.\\think\\Request::instance()->controller().'/save')}" id="form" method="post">
        <ul class="activity_list">
            <li>
                考试标题：
                <input type="text" class="txt" id="questionnaire_til" name="title" value="{$data.title ?? ''}" placeholder="您可以在这里创建您的考试题目，同时对考试活动加以说明">
            </li>
            <li>
                　关键词：
                <input type="text" class="txt" id="keyword" name="keyword" value="{$data.keyword ?? ''}">
            </li>
            <li id="explanation" style="display: list-item;">
                考试说明：
                <p>
                    <script id="editor" type="text/plain" name="description" >{$data.description|default=''|html_entity_decode ?? ''}</script>

                </p>
            </li>
            <li>
                开始时间：
                <span class="up_time" style="width:150px;">
                        <u id="t">
                        <input type="text" value="" id="starttime" style="margin-top:6px;width:125px;border:0px;" name="starttime" class="hasDatepicker" onClick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
                        </u>
                    </span>
            </li>
            <li>
                截至时间：
                <span class="up_time" style="width:150px;">
                        <u id="t">
                        <input type="text" value="" id="deadline" style="margin-top:6px;width:125px;border:0px;" name="dateline" class="hasDatepicker" onClick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
                        </u>
                    </span>
            </li>
        </ul>
        <div class="topic_box">
            <div class="question_box" id="question_info_1">
                <p class="question_info">
                    <span>问题<u>1</u>：</span>
                    <input type="text" class="txt" name="question[1]" value="请填写问题的题目" placeholder="请填写问题的题目">
                    <input type="text" class="answer" name="answer[1]" value="请填写题目的答案">
                    <input type="checkbox" class="checkd" name="ismulti[1]" id="ismulti_1" value="1">
                    <input type="hidden" class="hide_qid" name="qid[1]" id="qid[1]">
                    <label for="ismulti_1"> 允许多选</label>
                    <select name="ismulti[1]" class="typeselect">
                        <option value="0">单选</option>
                        <option value="1">多选</option>
                        <option value="2">自由填写</option>
                    </select>
                </p>
                <span class="insert_pic hidden">图片建议尺寸：150*100</span>
                <ul id="1" class="optionul">
                    <li>
                        <span>A</span><u>选项：</u>
                        <input type="hidden" class="hide_txt" name="oid[1][0]">
                        <input type="text" class="question"name="oldquestion[1][0]">
                        <input type="text" class="txt" name="option[1][0]">
                        <input type="hidden" class="image_class" name="image[1][0]" id="userfile_0"  >
                        <a class="list_del" href="javascript:;" title="删除这个选项">×</a>
                        <!--没传图片-->
                        <span class="no_pic hidden">
                                <a href="javascript:;" class="up" onclick="upyunPicUpload('userfile_0',700,700,'{pigcms:$token}')">
                                    <i></i>
                                    插入图片
                                    <input type="button" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100">
                                </a>
                                <div class="uppic_prompt">
                                    图片建议尺寸：<span>150*100</span>
                                    <div class="caret_Up"><em>◆</em><span>◆</span></div>
                                </div>
                            </span>
                        <!--传了图片-->
                        <span class="pic hidden" style="width:auto">
                                <a href="javascript:;">../fjdskjf.jpg</a>
                                <img src="" width="150" height="100">
                                <a href="javascript:;" class="del">×</a>
                            </span>
                    </li>
                    <li>
                        <span>B</span><u>选项：</u>
                        <input type="hidden" class="hide_txt" name="oid[1][1]">
                        <input type="text" class="question"name="oldquestion[1][1]">
                        <input type="text" class="txt" name="option[1][1]">
                        <input type="hidden" class="image_class" name="image[1][1]">
                        <a class="list_del" href="javascript:;" title="删除这个选项">×</a>
                        <!--没传图片-->
                        <span class="no_pic hidden">
                                <a href="javascript:;" class="up">
                                    <i></i>
                                    插入图片
                                    <input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100" id="userfile_1">
                                </a>
                                <div class="uppic_prompt">
                                    图片建议尺寸：<span>150*100</span>
                                    <div class="caret_Up"><em>◆</em><span>◆</span></div>
                                </div>
                            </span>
                        <!--传了图片-->
                        <span class="pic hidden" style="width:auto">
                                <a href="javascript:;">../fjdskjf.jpg</a>
                                <img src="" width="150" height="100">
                                <a href="javascript:;" class="del">×</a>
                            </span>
                    </li>
                    <li>
                        <span>C</span><u>选项：</u>
                        <input type="hidden" class="hide_txt" name="oid[1][2]">
                        <input type="text" class="question"name="oldquestion[1][2]">
                        <input type="text" class="txt" name="option[1][2]">
                        <input type="hidden" class="image_class" name="image[1][2]">
                        <a class="list_del" href="javascript:;" title="删除这个选项">×</a>
                        <!--没传图片-->
                        <span class="no_pic hidden">
                                <a href="javascript:;" class="up">
                                    <i></i>
                                    插入图片
                                    <input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100" id="userfile_2">
                                </a>
                                <div class="uppic_prompt">
                                    图片建议尺寸：<span>150*100</span>
                                    <div class="caret_Up"><em>◆</em><span>◆</span></div>
                                </div>
                            </span>
                        <span class="pic hidden" style="width:auto">
                                <a href="javascript:;">../fjdskjf.jpg</a>
                                <img src="" width="150" height="100">
                                <a href="javascript:;" class="del">×</a>
                            </span>
                    </li>
                    <li>
                        <span>D</span><u>选项：</u>
                        <input type="hidden" class="hide_txt" name="oid[1][3]">
                        <input type="text" class="question"name="oldquestion[1][3]">
                        <input type="text" class="txt" name="option[1][3]">
                        <input type="hidden" class="image_class" name="image[1][3]">
                        <a class="list_del" href="javascript:;" title="删除这个选项">×</a>
                        <!--没传图片-->
                        <span class="no_pic hidden">
                                <a href="javascript:;" class="up">
                                    <i></i>
                                    插入图片
                                    <input type="file" name="userfile" title="图片建议尺寸：150*100" alt="图片建议尺寸：150*100" id="userfile_2">
                                </a>
                                <div class="uppic_prompt">
                                    图片建议尺寸：<span>150*100</span>
                                    <div class="caret_Up"><em>◆</em><span>◆</span></div>
                                </div>
                            </span>
                        <span class="pic hidden" style="width:auto">
                                <a href="javascript:;">../fjdskjf.jpg</a>
                                <img src="" width="150" height="100">
                                <a href="javascript:;" class="del">×</a>
                            </span>
                    </li>
                </ul>
                <p class="bot_add"><a href="javascript:;" class="btnGrayS vm bigbtn"><img src="/images/product/add.png" width="16" class="vm">再添加一个选项</a></p>
            </div>
            <p class="add_questio"><a href="javascript:;" title="添加" class="btnGrayS vm bigbtn"><img src="/images/product/add.png" width="16" class="vm">再添加一题</a></p>
        </div>

        <ul>
            <ul class="pub_list">
                <li class="bot">
                    <input name="id" value="{$data.id ?? ''}"  type="hidden" />
                    <input type="hidden" value="{$data.cid ?? $addcid}" name="cidold" />
                    {:token()}
                        <input class="btn radius btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                        <input class="btn radius btn-default radius" type="reset" value="&nbsp;&nbsp;重置&nbsp;&nbsp;">
                    <!-- <button onClick="layer_close();" class="btn radius btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button> -->

                </li>
            </ul>
        </ul>



    </form>

</div>

{/block}